<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
%>

<div class="row">
    <div class="col-lg-12">
        <div class="panel">
            <div class="panel-heading header">
                <h3 class="panel-title" id="title">公司资质登记表</h3>
            </div>

            <!-- BASIC FORM ELEMENTS -->
            <!--===================================================-->
            <form id="form_cert_input" class="panel-body form-horizontal form-padding">
                <input type="hidden" name="keyId" id="keyId" value="${cert.id}" />
                <input type="hidden" name="curDutyId" id="curDutyId" value=""/>
                
                <div class="form-group">
                    <label class="col-md-2 control-label">资质类别<i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">

                        <div class="radio">
                            <!-- Inline radio buttons -->
                            <input type="radio" name="certType" id="certType1Selected" class="magic-radio" value="1"
                            <c:if test="${cert.certType==1}"> checked="checked"</c:if> >
                            <label for="certType1Selected">企业证照</label>

                            <input type="radio" name="certType" id="certType2Selected" class="magic-radio" value="2"
                            <c:if test="${cert.certType==2}"> checked="checked"</c:if> >
                            <label for="certType2Selected">企业资质</label>

                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">资质名称<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <select id="certDictItemId" name="certDictItemId" class="form-control">
                            <option></option>
                            <c:forEach var="item" items="${dictItems}" varStatus="status">
                                <option value="${item.id}" <c:if test="${item.id == cert.certDictItem.id}"> selected="selected"</c:if>>${item.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">证书/资质号<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text" id="certNo" name="certNo" class="form-control" placeholder="请输入证书/资质号" value="${cert.certNo}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        <a href="javascript:void(0);" onclick="fn_member_dialog_select()" style="color: #0a6dbd">办理人员</a>
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="userName" name="userName" class="form-control" placeholder="请选择办理人员" value="${cert.handler.name}">
                        <input type="hidden" id="userId" name="userId" value="${cert.handler.id}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">评定日期<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-2">
                            <div class="input-group date">
                                <input type="text" class="form-control" id="datEvaluate" name="datEvaluate" placeholder="请选择评定日期"
                                value=<fmt:formatDate pattern="yyyy-MM-dd" value="${cert.datEvaluate}" /> >
                                <span class="input-group-addon"><i class="ti-calendar"></i></span>
                            </div>
                    </div>
                    <label class="col-md-2 control-label">有效期限<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-2">
                        <div class="input-group date">
                            <input type="text" class="form-control" id="datValid" name="datValid" placeholder="请选择有效期"
                                   value=<fmt:formatDate pattern="yyyy-MM-dd" value="${cert.datValid}" /> >
                            <span class="input-group-addon"><i class="ti-calendar"></i></span>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">提交人</label>
                    <div class="col-md-2">
                        <p class="form-control-static">${cert.creater.name}</p>
                    </div>
                    <label class="col-md-2 control-label">提交日期</label>
                    <div class="col-md-2">
                        <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${cert.dateApply}" /></p>
                    </div>
                </div>

                <div class="panel-footer">
                    <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
                        <i class="fa fa-lg fa-mail-reply"></i> 返回
                    </a>
                    <a class="btn btn-success" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存 </a>
                    <c:if test="${cert==null || cert.processState=='Draft'}">
                        <a class="btn btn-warning" id="btn-commit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 提交 </a>
                    </c:if>
                    <c:if test="${cert!=null && cert.processState=='Backed'}">
                        <a class="btn btn-warning" id="btn-recommit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 再提交 </a>
                    </c:if>
                </div>
                
            </form>
            <!--===================================================-->
            <!-- END BASIC FORM ELEMENTS -->
            
        </div>
    </div>
</div>

<script>
    var index = "${index}";
    var todo = "${todo}";
    var remind = "${remind}";
    var record = "${record}";
    var draft =  "${draft}";

    $(function(){
        var pdata= {
            keyId:$("#keyId").val(),
            entityName:"com.fz.us.oa.core.entity.com.Certificate"
        };
        multiDuty(pdata);
    });

    // 日期选择
    $('.input-group.date').datepicker({
        format: 'yyyy-mm-dd',
        weekStart: 1,
        autoclose: true,
        todayBtn: 'linked',
        todayHighlight: true,
        language: 'zh-CN'
    });

    // 字典列表下拉框
    $("#certDictItemId").select2({
        placeholder: "请选择一个资质",
        allowClear: true
    });

    function fn_member_dialog_select() {
        __open_dialog_select('选择成员', '<%=path%>/main/member/dialog', function (dialogRef) {
            var callback = function (data) {
                if (data) {
                    dialogRef.close();

                    // 获取 user
                    $('#userId').val(data.id);
                    $('#userName').val(data.name)
                } else {
                    dialogRef.enableButtons();
                }
            };
            fn_dialog_member_select(callback);
        });
    }

    //校验
    function infoValidate() {
        var tmp = $("select#certDictItemId").val();
        if(!tmp){
            __toastr_error("请选择要使用的资质！");
            return false;
        }

        tmp = $("input#certNo").val();
        if(!tmp){
            __toastr_error("请输入证书/资质号！");
            return false;
        }

        tmp = $("input#userName").val();
        if(!tmp){
            __toastr_error("请选择办理人员！");
            return false;
        }

        tmp = $("input#datEvaluate").val();
        if(!tmp){
            __toastr_error("请选择评定日期！");
            return false;
        }

        tmp = $("input#datValid").val();
        if(!tmp){
            __toastr_error("请选择有效期限！");
            return false;
        }

        return true;
    }

    //保存
    $("#btn-save-common").click(
            function(e) {
                __confirm_dialog("提示：","确定保存吗？",
                        function () {
                            __form_save("form_cert_input", "<%=path%>/com/certificate/save",function(){
                                $("#apply-re-common").trigger("click");
                            });
                        }
                )
            }
    );

    //提交
    $("#btn-commit-common,#btn-recommit-common").click(
            function(e) {
                var $valid = infoValidate();
//                console.log("v:"+$valid);
                if(!$valid) return false;

                __confirm_dialog("提示：","提交后填写资料不得修改，请确认是否进行提交？",
                        function () {
                            __form_save("form_cert_input", "<%=path%>/com/certificate/commit",function(){
                                $("#apply-re-common").trigger("click");
                            });
                        }
                )
            }
    );

    //返回视图
    $("#apply-re-common").click(function(){

        if(index==1){
            loadURL("menu/dashboard",$('#page-content'));
        }else if(todo==1){
            loadURL("menu/toDo",$('#page-content'));
        }else if(remind==1){
            loadURL("menu/remind",$('#page-content'));
        }else if(record==1){
            loadURL("menu/taskRecord?type=1",$('#page-content'));
        }else if(record==2){
            loadURL("menu/taskRecord?type=2",$('#page-content'));
        }else if(draft==1){
            loadURL("menu/draft",$('#page-content'));
        }else{
            returnToHashUrl()
        }
    });


</script>




